import CODE from './code';
import { device, jumpToLogin } from '@/config/index';
import { Toast, Dialog } from 'vant';
import router from '@/router/router';
import store from '@/store/index';
export default function handleReponse(response, resolveCode = []) {
	let { code, msg, data } = response;
	let result = '';
	// 处理公共状态码，注意忽略需特殊处理的状态码(resolveCode)
	switch (code) {
		// 成功
		case CODE.Success:
			result = response;
			break;
		case CODE.tokenExpired:
			localStorage.removeItem('vuex');
			location.href = 'login';
			break;
		case CODE.tokenNot:
			Toast('没有token');
			break;
		// 未绑定手机
		case CODE.NotBindPhone:
			if (resolveCode.length && resolveCode.includes(code)) {
				result = response;
			} else {
				needBindPhone();
			}
			break;

		//其他情况用Taost返回msg
		default:
			if (resolveCode.length && resolveCode.includes(code)) {
				result = response;
			} else {
				result = response;
				Toast(msg || '网路出错，请重试');
			}
	}
	return result;
}
